﻿Imports System.Text.RegularExpressions

Public Class FormMarqueur

   

   


    Private Sub ButtonAnnuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAnnuler.Click
        If FormBrowser.Visible Then FormBrowser.Close()
        Me.Close()
    End Sub

    Private Sub ButtonOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOk.Click
        If Me.TextBoxTitre.Text <> "" And Me.TextBoxRegEx.Text <> "" Then
            Me.DialogResult = Windows.Forms.DialogResult.OK
            If FormBrowser.Visible Then FormBrowser.Close()
            Me.Close()
        End If
    End Sub

    Private Sub TextBoxTitre_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBoxTitre.Validating
        If Me.TextBoxTitre.Text = "" Then
            ErrorProvider1.SetError(Me.TextBoxTitre, "Le titre ne peut être vide")
        Else
            ErrorProvider1.SetError(Me.TextBoxTitre, "")
        End If
    End Sub

    Private Sub TextBoxRegEx_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBoxRegEx.Validating
        If Me.TextBoxRegEx.Text = "" Then
            ErrorProvider1.SetError(Me.TextBoxRegEx, "L'expression régulière ne peut être vide")
        Else
            ErrorProvider1.SetError(Me.TextBoxRegEx, "")
        End If
    End Sub

    Private Sub MarquerStyle(ByVal Marquer As Boolean)
        If Not RichTextBoxTest.SelectionFont Is Nothing Then
            Dim currentFont As System.Drawing.Font = RichTextBoxTest.SelectionFont
            Dim newFontStyle As System.Drawing.FontStyle
            If Marquer Then
                newFontStyle = FontStyle.Underline
            Else
                newFontStyle = FontStyle.Regular
            End If
            RichTextBoxTest.SelectionFont = New Font(currentFont.FontFamily, currentFont.Size, newFontStyle)
        End If
    End Sub

    Private Sub ButtonCoulFondPrimaire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCoulFondPrimaire.Click
        Me.ColorDialog1.SolidColorOnly = True
        Me.ColorDialog1.Color = System.Drawing.ColorTranslator.FromHtml(Me.TextBoxFondPrimaire.Text)
        If Me.ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.TextBoxFondPrimaire.Text = System.Drawing.ColorTranslator.ToHtml(Me.ColorDialog1.Color)
        End If
    End Sub

    Private Sub ButtonCoulFondSecondaire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCoulFondSecondaire.Click
        Me.ColorDialog1.SolidColorOnly = True
        Me.ColorDialog1.Color = System.Drawing.ColorTranslator.FromHtml(Me.TextBoxFondSecondaire.Text)
        If Me.ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.TextBoxFondSecondaire.Text = System.Drawing.ColorTranslator.ToHtml(Me.ColorDialog1.Color)
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.ColorDialog1.SolidColorOnly = True
        Me.ColorDialog1.Color = System.Drawing.ColorTranslator.FromHtml(Me.TextBoxTextePrimaire.Text)
        If Me.ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.TextBoxTextePrimaire.Text = System.Drawing.ColorTranslator.ToHtml(Me.ColorDialog1.Color)
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.ColorDialog1.SolidColorOnly = True
        Me.ColorDialog1.Color = System.Drawing.ColorTranslator.FromHtml(Me.TextBoxTexteSecondaire.Text)
        If Me.ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.TextBoxTexteSecondaire.Text = System.Drawing.ColorTranslator.ToHtml(Me.ColorDialog1.Color)
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        FormBrowser.WebBrowser1.DocumentText = My.Resources.SeparationHelp
        FormBrowser.Show()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.TextBoxFondPrimaire.Text = Commun.GetDefaultCoul(Me.TextBoxFondPrimaire.Text)
        Me.TextBoxFondSecondaire.Text = Commun.GetCoulComp(Me.TextBoxFondPrimaire.Text)
        Me.TextBoxTextePrimaire.Text = ColorTranslator.ToHtml(Color.Black)
        Me.TextBoxTexteSecondaire.Text = ColorTranslator.ToHtml(Color.Black)
    End Sub

  
    Private Sub TextBoxFondPrimaire_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxFondPrimaire.TextChanged
        TextBoxFondPrimaire.BackColor = System.Drawing.ColorTranslator.FromHtml(TextBoxFondPrimaire.Text)
        TextBoxTextePrimaire.BackColor = System.Drawing.ColorTranslator.FromHtml(TextBoxFondPrimaire.Text)
    End Sub

    Private Sub TextBoxTextePrimaire_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxTextePrimaire.TextChanged
        TextBoxTextePrimaire.ForeColor = System.Drawing.ColorTranslator.FromHtml(TextBoxTextePrimaire.Text)
        TextBoxFondPrimaire.ForeColor = System.Drawing.ColorTranslator.FromHtml(TextBoxTextePrimaire.Text)
    End Sub

    Private Sub TextBoxTexteSecondaire_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxTexteSecondaire.TextChanged
        TextBoxTexteSecondaire.ForeColor = System.Drawing.ColorTranslator.FromHtml(TextBoxTexteSecondaire.Text)
        TextBoxFondSecondaire.ForeColor = System.Drawing.ColorTranslator.FromHtml(TextBoxTexteSecondaire.Text)
    End Sub

    Private Sub TextBoxFondSecondaire_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxFondSecondaire.TextChanged
        TextBoxFondSecondaire.BackColor = System.Drawing.ColorTranslator.FromHtml(TextBoxFondSecondaire.Text)
        TextBoxTexteSecondaire.BackColor = System.Drawing.ColorTranslator.FromHtml(TextBoxFondSecondaire.Text)
    End Sub

    Private Sub ButtonImporter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonImporter.Click
        Me.OpenFileDialog1.Multiselect = False
        Me.OpenFileDialog1.Filter = "Tous|*.*"
        If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Try
                Me.TextBoxModele.Text = My.Computer.FileSystem.ReadAllText(Me.OpenFileDialog1.FileName, System.Text.Encoding.Default)
            Catch Ex As Exception
                MsgBox("Erreur à la lecture du fichier " & Me.OpenFileDialog1.FileName & ": " & Ex.Message, MsgBoxStyle.Exclamation)
            End Try
        End If
    End Sub

    Private Sub Tester()
        'Préparer un marqueur temporaire
        Dim oMarqueur As New ClassMarqueur
        oMarqueur.Titre = Me.TextBoxTitre.Text
        oMarqueur.sMasque = Me.TextBoxRegEx.Text
        oMarqueur.TestTexte = Me.RichTextBoxTest.Text
        oMarqueur.CoulFondPrimaire = Me.TextBoxFondPrimaire.Text
        oMarqueur.CoulFondSecondaire = Me.TextBoxFondSecondaire.Text
        oMarqueur.CoulTextePrimaire = Me.TextBoxTextePrimaire.Text
        oMarqueur.CoulTexteSecondaire = Me.TextBoxTexteSecondaire.Text
        oMarqueur.SensibleCasse = Me.CheckBoxCasse.Checked.ToString
        oMarqueur.Propager = Me.CheckBoxPropager.Checked.ToString
        'oMarqueur.Souligne = Me.CheckBoxSouligne.Checked.ToString
        oMarqueur.Multi = Me.CheckBoxMulti.Checked.ToString
        oMarqueur.AutoCoulTextePrimaire = Me.CheckBoxCoulAuto.Checked.ToString
        oMarqueur.Modele = Me.TextBoxModele.Text
        oMarqueur.CleTri = Me.TextBoxCleTri.Text
        oMarqueur.Condition = Me.TextBoxCondition.Text
        'Utiliser pour faire le test de marquage, d'extraction et de tri.
        oMarqueur.Marquer(Me.RichTextBoxTest)
        Me.RichTextBoxTri.Text = oMarqueur.Tri(Me.RichTextBoxTest.Text)
        oMarqueur.Marquer(Me.RichTextBoxTri)
        Me.RichTextBoxExtract.Text = oMarqueur.Extraire(Me.RichTextBoxTest.Text)
        oMarqueur = Nothing
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Call Me.Tester()
    End Sub

    Private Sub ButtonTester_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTester.Click
        Call Me.Tester()
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        FormBrowser.WebBrowser1.DocumentText = My.Resources.Condition
        FormBrowser.Show()
    End Sub

 
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Call Commun.VBScriptHelp()
    End Sub

    Private Sub CheckBoxCoulAuto_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxCoulAuto.CheckedChanged
        Me.TextBoxTextePrimaire.Enabled = Not Me.CheckBoxCoulAuto.Checked
        Me.Button1.Enabled = Not Me.CheckBoxCoulAuto.Checked
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Call Me.Tester()
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        FormBrowser.WebBrowser1.DocumentText = My.Resources.SeparationHelp
        FormBrowser.Show()
    End Sub

    Private Sub Button12_Click(sender As System.Object, e As System.EventArgs) Handles Button12.Click
        FormRegEx.TextBoxRegEx.Text = Me.TextBoxRegEx.Text
        FormRegEx.RichTextBoxTest.Text = Me.RichTextBoxTest.Text
        If FormRegEx.ShowDialog = DialogResult.OK Then Me.TextBoxRegEx.Text = FormRegEx.TextBoxRegEx.Text
    End Sub

    Private Sub FormMarqueur_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
        Me.ComboBoxMarqueurs.Items.Clear()
        For Each oItem As ListViewItem In Form1.ListViewMarqueurs.Items
            If oItem.Text <> Me.TextBoxTitre.Text Then Me.ComboBoxMarqueurs.Items.Add(oItem.Text)
        Next
    End Sub

    Private Sub ComboBoxMarqueurs_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBoxMarqueurs.SelectedIndexChanged
        Me.TextBoxRegEx.SelectedText = "%" & Me.ComboBoxMarqueurs.Text & "%"
    End Sub
End Class